package com.dhh.sky.util;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class FileViewer {
	private static List<File> fileList = new ArrayList<File>();	
	private static List<String> picFormat = new ArrayList<String>();
	
	static{
		picFormat.add("JPEG");
		picFormat.add("JPG");
		picFormat.add("TIFF");
		picFormat.add("RAW");
		picFormat.add("PNG");
		picFormat.add("BMP");
		picFormat.add("GIF");
	}
	
	public static List<File> getListFiles(String path) {
		fileList.clear();
		File file = new File(path);
		return FileViewer.listFile(file);
	}

	private static List<File> listFile(File f) {
		if (!f.isHidden() && f.isDirectory()) {
			File[] t = f.listFiles();
			for (int i = 0; i < t.length; i++) {
				listFile(t[i]);	
			}
		} else {
			if(picFormat.contains(getFileExt(f.getName()).toUpperCase())){
				fileList.add(f);
			}	
		}

		return fileList;
	}
	
	private static String getFileExt(String name){
		int sp = name.lastIndexOf(".");
		String ext = "";
		if(sp>=0){
			ext = name.substring(sp+1,name.length());
		}
		
		return ext;
	}
}
